import { del, get, patch, post } from '@/infrastructure/fetch'
import type { Notification, NotificationListResponse, NotificationParams } from './types'

const API_PREFIX = '/console/api'

// 获取通知列表
export const fetchNotifications = (params: NotificationParams): Promise<NotificationListResponse> => {
  return get<NotificationListResponse>(`${API_PREFIX}/notifications`, { params })
}

// 标记通知为已读
export const markNotificationAsRead = (notificationId: number): Promise<{ id: number }> => {
  return patch<{ id: number }>(`${API_PREFIX}/notifications/${notificationId}`)
}

// 标记所有通知为已读
export const markAllNotificationsAsRead = (): Promise<{ success: boolean }> => {
  return post<{ success: boolean }>(`${API_PREFIX}/notifications/mark-all-read`)
}

// 删除通知
export const deleteNotification = (notificationId: number): Promise<{ success: boolean }> => {
  return del<{ success: boolean }>(`${API_PREFIX}/notifications/${notificationId}`)
}

// 创建通知（管理员）
export const createNotification = (data: {
  title: string
  content: string
  type?: 'info' | 'warning' | 'error' | 'success'
  link?: string
}): Promise<{ id: number }> => {
  return post<{ id: number }>(`${API_PREFIX}/notifications`, { body: data })
}
